var page = require('webpage').create(),
    system = require('system'),
    url = 'http://guba.eastmoney.com/list,300519_',
    t = Date.now(),
    index = 1 , maxIndex = 50;

function saveData(model) {

}

function consoleText(index) {
  console.log('url => ' + url + index + '.html');
  page.open(url + index + '.html', function(status) {

    if (status !== 'success') {
      console.log('抓取错误');
    } else {
      console.log('抓取成功');
      var item = page.evaluate(function() {
        var list = [];
        var data = document.querySelectorAll('#articlelistnew > .articleh');

        for (var i = 0;i < data.length;i++) {
          list.push({
            title: data[i].querySelectorAll('.l3 a')[0].innerText,
            url: data[i].querySelector('.l4 a')
          })
        };

        return list;
      })

      for (var key in item) {
        console.log('title => ' + item[key].title);
        console.log('url => ' + item[key].url);
      }

      if (index < maxIndex) {
        setTimeout(function() {
          index++;
          consoleText(index);
        }, 6000);
      }
    }
  });
}

consoleText(1);
